package com.itheima.d1_reflect_method;

import org.junit.jupiter.api.Test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 触发方法
 */
public class demo2 {
    @Test
    public void getDeclaredMethods() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        Class c = Dog.class;

        Method m1 = c.getDeclaredMethod("eat", String.class);
        Method m2 = c.getDeclaredMethod("inAdd");
        m1.setAccessible(true);
        //invoke来触发方法
        Dog d = new Dog();
        String s1 = (String) m1.invoke(d,"哈士奇");
        System.out.println(s1);
        m2.invoke(d);


    }
}
